<script setup>
  import { ref, inject, onMounted } from 'vue';
  import { useRouter } from 'vue-router';
  import useDataStore from "@/stores/Data";
  import Car from "@/components/home-page/car.vue"

  // 使用 inject 钩子来获取通过 provide 提供的 showNavItem  
  const showNavItem = inject('showNavItem');

  // 使用 useRouter 钩子来获取路由实例  
  const router = useRouter();

  // 定义一个方法，用于导航到 '/front' 并显示导航项  
  const showNewNav = () => {
    router.push('/front/task');
    // 因为 showNavItem 本身就是一个 ref，所以直接设置其 value  
    if (showNavItem) {
      showNavItem.value = true;
    }
  };

  const useData = useDataStore();
  import { resHomeData } from '@/api/homes'

  onMounted(() => {
    useData.getHomeData()
  })

  const isExpanded = ref(false); // 使用 ref 创建一个响应式引用 
  const targetRotateDegrees = ref(0);

  function toggleExpansion() {
    isExpanded.value = !isExpanded.value; // 切换 isExpanded 的值 
    targetRotateDegrees.value = (targetRotateDegrees.value + 180) % 360;

  }
</script>

<template>
  <div class="Projectbox" :class="{ expanded: isExpanded }" :style="{
    transition: `max-height ${isExpanded ? '0.1s' : '0.1s'} ease-out`
  }">
    <div role="tablist" aria-multiselectable="true" class="collapse">
      <div class="active">
        <div role="tab">
          <div role="button" class="header ">
            <div class="title"> 更多 </div>
            <div class="downIconBox" @click="toggleExpansion">
              <div class="iconfont icon-mono-bottom" :style="{ transform: `rotate(${targetRotateDegrees}deg)` }"></div>
            </div>
            <i class="arrow"></i>
          </div>
        </div>

        <div role="tabpanel" aria-labelledby="el-collapse-head-1791" id="el-collapse-content-1791" class="wrap">
          <div class="content">
            <div class="courses courses3" @click="showNewNav">
              <Car v-for="item in useData.theHome" :name="item.name" :desc="item.currDesc" :img="item.iconPath"
                :time1="item.startTeachingTime" :time2="item.startTeachingTime" :id="item.currNo" />

            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
  .Projectbox.expanded {
    max-height: 100px;
  }

  .Projectbox {
    margin-bottom: 43px;
    width: 1320px;
    max-height: 1000px;
    overflow: hidden;
    transition: all .1s linear;


  }

  .iconfont {
    margin-right: 20px;
    transition: transform 0.5s ease;
  }

  div {
    box-sizing: border-box;
    display: block;
    unicode-bidi: isolate;
  }

  .collapse {
    border-top: 1px solid #EBEEF5;
    border-bottom: 1px solid #EBEEF5;
    border: none;
    background-color: #fff;
    box-shadow: 0 10px 6px 0 rgba(19, 18, 18, .16);
    border-radius: 20px;
    border: 1px solid hsla(0, 0%, 85.1%, .5);
    overflow: hidden;

  }

  .active:last-child {
    margin-bottom: -1px;

  }

  .collapse .active .header {
    height: 80px;
  }

  .header {
    padding: 0 60px;
    border: none;
    margin-left: 12px;
    border-bottom-color: transparent;
    display: flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    height: 48px;
    line-height: 48px;
    background-color: #FFF;
    color: #303133;
    cursor: pointer;
    border-bottom: 1px solid #EBEEF5;
    font-size: 13px;
    font-weight: 500;
    -webkit-transition: border-bottom-color .3s;
    transition: border-bottom-color .3s;
    outline: 0;
  }

  .downIconBox img {
    -webkit-user-select: none;
    -moz-user-select: none;
    user-select: none;
    width: 100%;
    height: 100%;

  }

  .downIconBox {
    transform: rotate(180deg);
    margin: 0 0 0 10px;
    transition: transform .3s;
  }

  .title {
    margin: 0 !important;
    flex: 1;
    text-align: center;
    margin-right: 50px;
    position: relative;
    font-family: Segoe UI;
    font-size: 16px;
    font-weight: 700;
    color: #707070;
  }

  .wrap {
    padding: 0 1px;
    border: none;
    will-change: height;
    background-color: #FFF;
    overflow: hidden;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    border-bottom: 1px solid #EBEEF5;
    margin-top: 30px;
  }

  .content {
    padding-bottom: 25px;
    font-size: 13px;
    color: #303133;
    line-height: 2;
  }

  .courses {
    margin-left: 23px;
    display: flex;
    align-items: center;
    flex-flow: row wrap;
  }

  @media only screen and (max-width: 603px) {
    .courses {
      justify-content: center !important;
    }
  }

  .course {
    cursor: pointer;
    padding: 4px 10px 0;
    margin-bottom: 15px;
    margin-left: 30px;
    margin-right: 30px;
    width: 240px;
    height: 270px;
    background-color: #fff;
    border-radius: 8px;
    border: 1px solid #fff;
  }

  .shadow {
    box-shadow: 0 1px 5px 0 rgba(0, 0, 0, .16);
    transition: box-shadow .2s linear;
  }

  .desc,
  .name {
    word-break: break-all;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .name {
    margin-top: 8px;
    font-family: Segoe UI;
    font-size: 18px;
    color: #707070;
  }

  .time {
    font-family: Segoe UI;
    font-size: 14px;
  }

  .iconPathBox img {
    -o-object-fit: cover;
    object-fit: cover;
    width: 220px;
    height: 135px;
    border-radius: 8px;
  }

  .iconBox img {
    margin-left: 80px;
    margin-top: 20px;
  }

  img {
    vertical-align: middle;
    border-style: none;
    width: 70px;

  }
</style>